package top.zlhy7.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;

/**
 * @author 任勇
 * @date 2021/12/23 8:43
 * @description RestTemplate配置类
 */
@Configuration
public class RestTemplateConfig {
    @Bean
    public RestTemplate restTemplate(){
        SimpleClientHttpRequestFactory httpRequestFactory = new SimpleClientHttpRequestFactory();
        httpRequestFactory.setReadTimeout(3500);
        httpRequestFactory.setConnectTimeout(5000);
        SocketAddress address = new InetSocketAddress("proxy.xa.petrochina", 8080);
        Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
        //没有代理就不用配下面这句
        httpRequestFactory.setProxy(proxy);
        return new RestTemplate(httpRequestFactory);
    }
}
